import os

BASE_TEMPLATE='''
#ifndef [FNAME_DEF]
#define [FNAME_DEF]

[CONTENT]

#endif
'''
# 收集目录下所有的头文件并汇总
def c_header_collect(root='.', fname='include.h'):
    fname_def = '__' + fname.upper().replace('.', '_') + '__'
    content = []
    for f in os.listdir(root):
        if f.endswith('.h'):
            content.append('#include "'+ f +'"')
    content = '\n'.join(content)
    with open(os.path.join(root, fname), 'w') as fp:
        fp.write(
            BASE_TEMPLATE
            .replace('[FNAME_DEF]', fname_def)
            .replace('[CONTENT]', content)
        )